<?php

/*
* Register a new user. This will insert a name and password
* into the members table.
*
* @method post
* @header username The username to be added to the database
* @header password The password associated with the user. Javascript
* should be md5 hashing this before it gets here, but we need to check
* anyway and md5 hash it if it has not been.
*
* @return 'User successfully created'
*           If the sql insertion returned true and username was added
* @return 'Username already exists'
*           If the SQL insert fails. Presumable, it is due to the username existing.
* @return 'Did not recieve a username or password'
*           If either the username or password headers were null
* @return 'Username cannot contain spaces'
*           If the username contains any spaces
*/

include("connect_to_database.php");

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);

if(!$username || !$password)
	die("Did not recieve a username or password");

if(strstr($username," "))
	die("Username cannot contains spaces");

$query = sprintf("INSERT INTO members (username,password) values('%s','%s');", $username, md5($password));
$result = mysql_query($query); 

if($result)
	echo "User successfully created";
else
	echo "Username already exists"
	
?>
